package com.yes.xr;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class AppReffect {
    public static void main(String[] args) throws Exception{
        Class<?> A = Class.forName("com.yes.yll.Animal");
        Object o = A.newInstance();
        Field[] fields = A.getDeclaredFields();
        for(int i=0;i<fields.length;i++){
            Field field = fields[i];
            field.setAccessible(true);
            Class<?> type = field.getType();
            if(type.toString().endsWith("String")){
                field.set(o,"Timor");
            }
            if(type.toString().endsWith("Integer")){
                field.set(o,2);
            }
            if(type.toString().endsWith("double")){
                field.set(o,3.14);
            }
        }
        Method say = A.getDeclaredMethod("say");
        say.invoke(o);
    }
}
